package com.detroitchow;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.drawable.Drawable;
import com.detroitchow.mapviewballoons.BalloonItemizedOverlay;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

public class MyItemizedOverlay extends BalloonItemizedOverlay<MyOverlayItem> {

	private Context context=null;
	private Drawable marker=null;
	private MyOverlayItem myOverlayItem;
	private GeoPoint point;
	private ArrayList<MyOverlayItem> mOverlays = new ArrayList<MyOverlayItem>();
	
	public MyItemizedOverlay(Drawable defaultMarker, MapView mapView) {
	 // super(defaultMarker);
		super(boundCenter(defaultMarker), mapView);
		this.context = mapView.getContext();
		this.marker = defaultMarker;
  }

	
	
	public void addOverlayItem(double lat, double lng, String title, Drawable altMarker) {
		point = new GeoPoint((int)(lat * 1E6), (int)(lng * 1E6));
		MyOverlayItem overlayItem = new MyOverlayItem(point, title, null, 0);
    myOverlayItem = overlayItem;
    marker = altMarker;
    addOverlayItem(overlayItem, marker);
	}
	
	public void addOverlayItem(double lat, double lng, String title, String snippet, int sid) {
		GeoPoint point = new GeoPoint((int)(lat * 1E6), (int)(lng * 1E6));
    MyOverlayItem overlayItem = new MyOverlayItem(point, title, snippet, sid);
    addOverlayItem(overlayItem, this.marker);
	}

  public void addOverlayItem(MyOverlayItem overlayItem) {
  	  mOverlays.add(overlayItem);
  	  populate();
  }

  public void addOverlayItem(MyOverlayItem overlayItem, Drawable altMarker) {
      overlayItem.setMarker(boundCenterBottom(altMarker));
      addOverlayItem(overlayItem);
  }
  
  public void addAllOverlays(ArrayList<MyOverlayItem> items) {
  	mOverlays.addAll(items);
  	populate();
  }

	@Override
  protected MyOverlayItem createItem(int i) {
	  // TODO Auto-generated method stub
		return mOverlays.get(i);
  }

	@Override
  public int size() {
	  return mOverlays.size();
  }
	
	public OverlayItem getOverlayItme() {
		return myOverlayItem;
	}
	
	public GeoPoint getPoint() {
		return point;
	}
	
	public void pop() {
		populate();
	}
	
	
	@Override
	protected boolean onBalloonTap(int index, MyOverlayItem item) {
		return true;
	}
	
	public void autoSelect(int i) {
		//Log.i("MyItemizedOverlay", "autoSelect i:" + i);
		this.onTap(i);
	}
	
	public ArrayList<MyOverlayItem> getOverLayItems() {
		return mOverlays;
	}
	
	public void setOverrideOverlaytItem(int i, MyOverlayItem item) {
		mOverlays.set(i, item);
	}
	
}
